package com.shigi.sat.structure;

/**
 * Created by Miroslav Šiagi on 28/01/15.
 */
public class SatClausule {
    private final int numOfLiterals;
    public final SatLiteral[] literals;

    private SatInstance itsSatInstance;

    public SatClausule(int numOfLiterals, SatInstance itsSatInstance) {
        this.numOfLiterals = numOfLiterals;
        this.itsSatInstance = itsSatInstance;
        this.literals = new SatLiteral[this.numOfLiterals];

        for (int i = 0; i < this.numOfLiterals; i++) {
            this.literals[i] = new SatLiteral(this.itsSatInstance);
        }
    }

    public SatClausule(SatClausule satClausule, SatInstance itsSatInstance) {
        this.numOfLiterals = satClausule.numOfLiterals;
        this.itsSatInstance = itsSatInstance;
        this.literals = new SatLiteral[this.numOfLiterals];

        for (int i = 0; i < this.numOfLiterals; i++) {
            this.literals[i] = new SatLiteral(satClausule.literals[i], itsSatInstance);
        }
    }

    public boolean evaluateLiterals() {
        boolean evaluatedValue = false;
        for (int i = 0; i < numOfLiterals && !evaluatedValue; i++) {
            evaluatedValue = evaluatedValue | this.literals[i].evaluate();
        }
        return evaluatedValue;
    }
}
